<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>重置密码</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style>
        .inpView{
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            border: #eeeeee solid 1px;
            font-size: 12px;
            line-height: 22px;
            padding: 0 6px;
        }

    </style>
</head>
<body class="iframeBody"onload="load()">
<div class="Wrapper">
    <form id="formSet1" >
        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_100_auto">
                <div class="label">工号</div>
                <div class="field">
                    <input name="usrNm" id="usrNm" type="text" class="ui-textbox inpView"
                           value="" placeholder="请填写工号" validate="{required:true, maxlength:20}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">身份证号</div>
                <div class="field">
                    <input name="certNo" id="certNo" type="text" class="ui-textbox inpView"
                             value="" placeholder="请填写身份证号" validate="{required:true, maxlength:20}">
                    <span class="requiredSymbol">*</span>
                    </span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">手机号</div>
                <div class="field">
                    <input name="usrMp" id="usrMp" type="text" class="ui-textbox inpView"
                           value="" placeholder="请填写手机号信息" validate="{required:true, maxlength:11}">
                    <span class="requiredSymbol">*</span>
                    </span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">图形码</div>
                <div class="field">
                    <input name="verifyImg" id="verifyImg" type="text" class="ui-textbox inpView"
                           value="" placeholder="图形码" validate="{required:true, maxlength:4}"
                           ligerui="width:80">
                    <span class="getVerifyImg">
                           <img width="80" height="24" id="kaptcha" onClick="changeKaptcha(this)"/>
                    </span>
                </div>
            </div>
            <div class="fieldBox col_100_auto" style="cursor: pointer;">
                <div class="label">短信验证码</div>
                <div class="field">
                    <input name="verifyCd" id="verifyCd" type="text" class="ui-textbox inpView"
                           value="" placeholder="手机验证码" validate="{required:true, maxlength:4}">
                    <span class="getVerifyCd" onclick="getPhoneCode(this)">获取验证码</span>
                </div>
            </div>
        </div>
    </form>
</div>


<script type="text/javascript">
    function load(){
        changeKaptcha(document.getElementById("kaptcha"));
    }
    var uid;

    /*
     *更新图片验证码
     */
    function changeKaptcha(obj) {
        debugger
        uid = Date.now().toString(36)+Math.random().toString(36).substr(3);
        obj.src = "<%=path%>/system/sysUsrPwd/kaptcha.do?uid=" + uid + "&r=" + Math.floor(Math.random() * 100);
    }

    /*
    *获取手机验证码
    */
    function getPhoneCode(obj) {
        var _verifyImg = $("#verifyImg").val();
        var _usrNm = $("#usrNm").val();


        if (_usrNm == "" || _usrNm == null || _usrNm == undefined) {
            top.$.ligerDialog.SQalert({content: "请输入用户名", SQ_type: "warning"});
            return;
        } else if (_verifyImg == "" || _verifyImg == null || _verifyImg == undefined) {
            top.$.ligerDialog.SQalert({content: "请输入图片验证码", SQ_type: "warning"});
            return;
        } else {
            var _url = '<%=path%>/system/sysUsrPwd/getPhoneAuthCd.do';
            $.ajax({
                type: 'get',
                dataType: 'json',
                data: {
                    uid: uid,
                    usrNm: _usrNm,
                    verifyImg: _verifyImg
                },
                url: _url,
                xhrFields: {
                    withCredentials: true
                },
                success: function (msg) {
                    console.info(msg)
                    if (msg.data == 1) {
                        var fieldBoxList = document.getElementsByClassName("fieldBox")
                        for (var i = 0, len = fieldBoxList.length; i < len; i++) {
                            console.log(fieldBoxList[i])
                            fieldBoxList[i].style.marginBottom = 5 + "px"
                        }
                        $("#verifyView").show();
                        changeKaptcha(document.getElementById("kaptcha"));
                    }
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        settime(obj);
                    } else {
                        changeKaptcha(document.getElementById("kaptcha"));
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
    }

    var countdown = 60;

    function settime(obj) { //发送验证码倒计时
        debugger
        if (countdown == 0) {
            $(obj).removeClass("disabledBtn")
            $(obj).text("获取验证码");
            countdown = 60;
            return;
        } else {
            $(obj).addClass("disabledBtn")
            $(obj).text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
            settime($(obj))
        }, 1000)
    }

    frameElement.dialog.onCancel = function(){
        parent.$.ligerDialog.close();
        parent.$(".l-dialog,.l-window-mask").css("display","none");
    }

    frameElement.dialog.onOk = function () {
        var _verifyCd = $("#verifyCd").val();
        var _usrNm = $("#usrNm").val();
        var _usrMp = $("#usrMp").val();
        var _certNo = $("#certNo").val();
        if (_usrNm == "" || _usrNm == null || _usrNm == undefined) {
            top.$.ligerDialog.SQalert({content: "请输入用户名", SQ_type: "warning"});
            return;
        } else if (_verifyCd == "" || _verifyCd == null || _verifyCd == undefined) {
            top.$.ligerDialog.SQalert({content: "请输入短信验证码", SQ_type: "warning"});
            return;
        }else if (_usrMp == "" || _usrMp == null || _usrMp == undefined) {
            top.$.ligerDialog.SQalert({content: "请输入手机号码", SQ_type: "warning"});
            return;
        }else if (_certNo == "" || _certNo == null || _certNo == undefined) {
            top.$.ligerDialog.SQalert({content: "请输入证件号码", SQ_type: "warning"});
            return;
        } else {
            var _url = '<%=path%>/system/sysUsrPwd/verifyIdentity.do';
            $.ajax({
                type: 'get',
                dataType: 'json',
                data: {
                    usrNm: _usrNm,
                    verifyCd: _verifyCd,
                    usrMp:_usrMp,
                    certNo:_certNo
                },
                url: _url,
                xhrFields: {
                    withCredentials: true
                },
                success: function (msg) {
                    if (msg.success == 1) {
                        parent.$.ligerDialog.SQopen({
                            width: 500,
                            height:200,
                            title : '设置密码',
                            url:'<%=path%>/system/sysUsrPwd/toUsrPwdResetPage.do?cacheKey=' + msg.data.cacheKey + "&usrId=" + msg.data.usrId,
                            buttons: [{
                                text: "确认", type: 'ok', cls: 'sq-button sq-button-round',
                                onclick: function (item, Dialog) {
                                    if (Dialog.onOk) Dialog.onOk();
                                }
                            }, {
                                text: "取消", type: 'cancel', cls: 'sq-button sq-button-round',
                                onclick: function (item, Dialog) {
                                    if (Dialog.onCancel) Dialog.onCancel();
                                }
                            }
                            ]
                        });
                        frameElement.dialog.close();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
    };

</script>
</body>
</html>
